package org.vvps.word;

import java.io.IOException;
import java.util.StringTokenizer;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.MapReduceBase;
import org.apache.hadoop.mapred.Mapper;
import org.apache.hadoop.mapred.OutputCollector;
import org.apache.hadoop.mapred.Reporter;

public class WordMap extends MapReduceBase implements Mapper<LongWritable, Text, Text, IntWritable> {
	private final static IntWritable one = new IntWritable(1); 
	private Text word = new Text(); 
	@Override
	public void map(LongWritable key, Text value,
			OutputCollector<Text, IntWritable> output, Reporter arg3)
			throws IOException {
		 String line = value.toString(); 
		 StringTokenizer tokenizer = new StringTokenizer(line); 
		 while (tokenizer.hasMoreTokens()) { 
			  word.set(tokenizer.nextToken()); 
			  output.collect(word, one); 
		 }
		 word.set("key="+key.toString());
		 output.collect(word, one);
		
	}

}
